JWeiboWidgetOption = {
    bindUrl:'',
    showUrl:'',
    bindedUrl:'',
    oauthUrl:'',
    weiboId:''
};

function JWeiboWidget (options){
  
  JWidget.apply(this,arguments);

}
JWeiboWidget.prototype.__proto__ = JWidget.prototype;

JWeiboWidget.prototype.init = function(){
  /*
   * 调用父类方法
   */
  JWidget.prototype.init.apply(this,arguments);
  

  var me = this;
  
    var me = this;
  items['文字颜色']=$('<div><div/>').addClass('colorbutton').click(function(){me.pickerColor(this,'color');});
  $.extend(true,this.configItems,items);
  
//  var weiboConfigItems = [$('<button/>').text('更新微博').click(function(){ 
//                            me.weiboConfig();
//              }) 
//               ];
               
               //这里有问题。不知道怎么写。。。。
               // var weiboConfigItems =[$('body').load(function(){me.weiboConfig();})];
//  this.configItems = $.extend(true,weiboConfigItems ,this.configItems);
};

JWeiboWidget.prototype.run = function(){
  /*
   * 调用父类方法
   */
  JWidget.prototype.run.apply(this,arguments);
  this.show();
};

JWeiboWidget.prototype.weiboConfig = function(){
  // alert('JWeiboWidgetOption.bindUrl');
  //var weiboConfigBox = $('<div/>').attr('id','weiboConfigBox').load(JWeiboWidgetOption.bindUrl).dialog({modal:true,width:500,height:400});
   var me = this;
   window.weiboBind = function(result){
     if(result.status && result.status == true){
       me.field('pid',result.pid);
     }else{
       
     }
     setTimeout(function(){ 
       //alert('upid=='+me.fields.upid);
       //me.core.load($('<div/>').text("Image loaded"));
        $('div.ui-dialog').has('iframe').remove();
      
    	 me.core.load(JWeiboWidgetOption.bindUrl,{pid:me.options.wbid.pid});  
          
     },30); 
   };
};

JWeiboWidget.prototype.weiboBinded = function(){
  
  
};


/**
 * invoke controller.show to display weibo content.
 * @return
 */
JWeiboWidget.prototype.show = function(){
  /*
   * 
   */
   var p_id;
   // if(typeof this.options.wbid=="undefined"){
   //   p_id=this.fields.pid;
   // }else{
   //   p_id=this.options.wbid.pid;
   // }
   // 
  if(typeof this.fields.pid=="undefined"){
     this.fields.pid=this.options.wbid.pid;
   }
   p_id=this.fields.pid;
   
 	this.core.load(JWeiboWidgetOption.bindUrl,{pid:p_id});
//	alert(JWeiboWidgetOption.bindUrl);
	var me=this;
	window.weiboUP = function(up){
		if(eval(up)=="" ){
			var iIframe =  $("<iframe/>").css({width:'100%',height:'100%'}).attr("src",JWeiboWidgetOption.oauthUrl);    
		    $('<div/>').css({width:'100%',height:'100%',overflow:'hidden'}).append(iIframe)
		    .dialog({width:650,height:450,modal:true});
		    me.weiboConfig();
		}else{
			var json=eval(up);
			me.core.load(JWeiboWidgetOption.showUrl,json[0]);
		}
	}
};

JWeiboWidget.prototype.resized = function(event, ui){
	
	var len=this.core.css('height').substring(0,this.core.css('height').indexOf('px'));
	$('.wblist').css('height',len-100);
};
// JWeiboWidget.prototype.initConfigBar = function(){
//   JWidget.prototype.initConfigBar.apply(this,arguments);
//   var me = this;
//   items['áWúr']=$('<div><div/>').addClass('colorbutton').click(function(){me.pickerColor(this,'color');});
//   $.extend(true,this.configItems,items);
// };
